list gMenu=[];
list statesMenu=[0,0,0,0];
list gAvatarAllow;
key ToucherID;
integer gMenuLink =1337;
integer gDemon =1338;
integer gPlugin =1339;
integer gVic =1329;
integer channel_dialog;
integer listen_id;
integer listen_id2;
string msg;
float gdistance;
list color =["Pink","White","Black","Red","Blue"];
integer attachment = TRUE;
integer relaychannel = -1812221819;
string cmdname;
key victim;
integer crossing=0;
integer random;
vector gColor;
string gMessage="♥";
integer sideScript = 1234;
integer sideScript2 = 1235;
//
displayMenu()
{
	gMenu=[];
	gMenu+="Back";
	gMenu+="Set New";
	if(llList2Integer(statesMenu,0)==1)gMenu+="[x]Hide";
    else gMenu+="[ ]Hide";
	gMenu+=color;
	msg = "Pick one";
	channel_dialog = ( -1 * (integer)("0x"+llGetSubString((string)llGetKey(),-5,-1)) );
	listen_id = llListen( channel_dialog, "", NULL_KEY, "");
	llDialog(ToucherID, msg,gMenu, channel_dialog);
	llSetTimerEvent(45.0);
}

MakeRLVState()
{
    if(attachment==TRUE)
    {
        //onRez we make this to be secure if its an attachmentttt
        if(llList2Integer(statesMenu,0)==1)llMessageLinked(LINK_SET, sideScript2, "off", NULL_KEY);
    }
}

llRlvSay(string command)
{
    if(attachment==TRUE)
    {
        llOwnerSay("@"+command);
    }
    else
    {
        llSay(relaychannel,cmdname + "," + (string)victim  + "," + "@"+command);
    }
}

llLRP(integer element_new, integer placeinlist)
{
	statesMenu = llListReplaceList(statesMenu, [element_new], placeinlist, placeinlist);
}

default {
    state_entry() 
    {
    	
    }
     listen(integer channel, string name, key id, string message)
    {
    	if(channel==channel_dialog)
    	{
			llListenRemove(listen_id);
			if(message=="Pink")
			{
				gColor= <1.0, 0.0, 1.0>;
				llMessageLinked(LINK_SET, sideScript, gMessage+"||"+(string)gColor, NULL_KEY);
				displayMenu();
			}
			else if(message=="White")
			{
				gColor= <1.0, 1.0, 1.0>;
				llMessageLinked(LINK_SET, sideScript, gMessage+"||"+(string)gColor, NULL_KEY);
				displayMenu();
			}
			else if(message=="Black")
			{
				gColor= <0.0, 0.0, 0.0>;
				llMessageLinked(LINK_SET, sideScript, gMessage+"||"+(string)gColor, NULL_KEY);
				displayMenu();
			}
			else if(message=="Red")
			{
				gColor=<1.0, 0.0, 0.0>;
				llMessageLinked(LINK_SET, sideScript, gMessage+"||"+(string)gColor, NULL_KEY);
				displayMenu();
			}
			else if(message=="Blue")
			{
				gColor=<0.0, 0.0, 1.0>;
				llMessageLinked(LINK_SET, sideScript, gMessage+"||"+(string)gColor, NULL_KEY);
				displayMenu();
			}
			else if(message=="Set New")
			{
				float grand=llFrand(13333337);
                random= llRound(grand);
                listen_id = llListen( random, "", ToucherID, "");
                llInstantMessage(ToucherID, "Set new Sign on:"+(string)random );
			}
			else if(message=="Back")
			{
				llMessageLinked(LINK_THIS, gMenuLink, "DV_MAIN_MISC", ToucherID);
			}
			else if(message=="[x]Hide")
			{
				llMessageLinked(LINK_SET, sideScript2, "on", NULL_KEY);
				llLRP(0,0);
				displayMenu();
			}
			else if(message=="[ ]Hide")
			{
				llLRP(1,0);
				llMessageLinked(LINK_SET, sideScript2, "off", NULL_KEY);
				displayMenu();
			}
    	}
    	if(channel==random)
    	{
    		gMessage=message;
    		llMessageLinked(LINK_SET, sideScript, gMessage+"||"+(string)gColor, NULL_KEY);
    	}
    	
    }
    
    link_message(integer sender, integer num, string str, key id)
  	{
  		
  		if(num ==gMenuLink)
  		{
  			if(str==llGetScriptName())
  			{
  				llMessageLinked(LINK_THIS, gDemon, llGetScriptName(), NULL_KEY);
  				ToucherID=id;
  				displayMenu();
  			}
  		}
  		if(num ==gDemon)
  		{
  			if(str!=llGetScriptName())
  			{
				llListenRemove(listen_id);
  			}
  		}
  		if(num==gPlugin)
  		{
  			if(str=="ON_REZ")
  			{
  				MakeRLVState();
  			}
  			if(str=="RESET")
  			{
  				statesMenu=[0,0,0,0,0,0,0,0,0,0];  				
  			}
  		}
  	}
  	
  	on_rez(integer num)
    {
             
    }
  	

  	
  	timer()
  	{
  		llSetTimerEvent(0.0);
  		llListenRemove(listen_id);
  	}
}
